package com.ryandj.config.shiro;

import com.ryandj.encrypt.Pbkdf2Sha256;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.authc.credential.CredentialsMatcher;

/**
 * Created by wdj on 2024/6/11
 */


public class Pbkdf2Sha256CredentialsMatcher implements CredentialsMatcher {
    @Override
    public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) {
        UsernamePasswordToken userToken = (UsernamePasswordToken) token;
        String plainPassword = new String(userToken.getPassword());
        String storedPassword = (String) info.getCredentials();
        return Pbkdf2Sha256.verification(plainPassword, storedPassword);
    }
}
